home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SAT 2.3b4 / Demo ƒ / Collision][ demo ƒ / sMrEgghead.c < prev    next >
Text File  |  1994-08-21  |  2KB  |  66 lines

  1. /* Player sprite for SATcollision][ */
  2.  
  3. /*unit sMrEgghead;*/
  4.  
  5. #include "SAT.h"
  6. #include "Collision][.h"
  7.  
  8.     FacePtr    mrEggheadFaces[4];
  9.     FacePtr    yuckFace;
  10.  
  11.  
  12.     void InitMrEgghead()
  13.     {
  14.         int i;
  15.         
  16.         for(i=0;i<=3;i++)
  17.             mrEggheadFaces[i] = SATGetFace(128 + i);
  18.         yuckFace = SATGetFace(134);
  19.     }
  20.  
  21.     pascal void SetupMrEgghead (SpritePtr me)
  22.     {
  23.         me->mode = 0;
  24.         me->speed.h = 1;
  25.         me->kind = 1; /*Friend kind*/
  26.         SetRect(&me->hotRect, 0, 0, 32, 32);
  27.         me->task = HandleMrEgghead;
  28.         me->hitTask = HitMrEgghead;
  29.     }
  30.  
  31.     pascal void HandleMrEgghead (SpritePtr me)
  32.     {
  33.         GetMouse(&me->position);
  34.  
  35. /*This time, let's make sure Mr Egghead is always visible!*/
  36.         if (me->position.v < 0)
  37.             me->position.v = 0;
  38.         if (me->position.h < 0)
  39.             me->position.h = 0;
  40.         if (me->position.v > gSAT.offSizeV - 32)
  41.             me->position.v = gSAT.offSizeV - 32;
  42.         if (me->position.h > gSAT.offSizeH - 32)
  43.             me->position.h = gSAT.offSizeH - 32;
  44.  
  45.  
  46.         if (me->mode < 0) /*we have taken a bite in a bad apple recently*/
  47.             {
  48.                 me->face = yuckFace;
  49.                 me->mode = me->mode + 1;
  50.             }
  51.         else if (me->mode == 0) /*nothing special recently*/
  52.             me->face = mrEggheadFaces[2];
  53.         else
  54.             { /*ate an apple recently - chew!*/
  55.                 me->mode = me->mode - 1;
  56.                 me->face = mrEggheadFaces[me->mode % 4];
  57.             };
  58.     }
  59.  
  60.     pascal void HitMrEgghead (SpritePtr me, SpritePtr him)
  61.     {
  62. /* Hit something! We can take whatever action we need here, but in this case,*/
  63. /* we let sApple decide. (We could have omitted this function altogether */
  64. /* and passed nil as hittask to NewSprite.)*/
  65.     }
  66.